package com.ykt.model;

import com.jfinal.plugin.activerecord.Page;
import com.ykt.common.utils.PageUtil;
import com.ykt.common.utils.page.PageData;
import com.ykt.common.utils.page.PageParam;

/**
 * 萤石视频直播源
 * @author long.hua
 * @version 1.0.0
 * @since 2016-01-09 20:30
 */
public class Camera extends BaseModel<Camera> {
    private static final long serialVersionUID = 1L;

    public static final String device_id = "device_id";
    public static final String device_serial = "device_serial";
    public static final String device_name = "device_name";
    public static final String camera_id = "camera_id";
    public static final String camera_no = "camera_no";
    public static final String camera_name = "camera_name";
    public static final String status = "status";
    public static final String is_shared = "is_shared";
    public static final String pic_url = "pic_url";
    public static final String is_encrypt = "is_encrypt";
    public static final String defence = "defence";

    public static final Camera dao = new Camera();


    /**
     * 根据shop Id查询其所有摄像头的全部信息
     *
     * @param param
     * @return
     */
    public PageData<Camera> pageFindByShopId(PageParam<Integer> param) {
        String select = "SELECT c.* ";
        String exceptSelect = " FROM camera c, camera_shop s WHERE c.id=s.camera_id AND s.shop_id=? AND c.status=1";

        Page<Camera> page = this.paginate(param.getPageNo(), param.getPageSize(), select, exceptSelect, param.getP());
        return PageUtil.to(page);
    }

    /**
     * 根据shop Id查询其所有摄像头的主要信息
     *
     * @param param
     * @return
     */
    public PageData<Camera> pageFindTinyCameraByShopId(PageParam<Integer> param) {
        String select = "SELECT c.camera_id, c.device_id, c.device_serial, c.pic_url ";
        String exceptSelect = " FROM camera c, camera_shop s" +
                " WHERE c.id=s.camera_id AND s.shop_id=? AND c.status=1";

        Page<Camera> page = this.paginate(param.getPageNo(), param.getPageSize(), select, exceptSelect, param.getP());
        return PageUtil.to(page);
    }

    /**
     * 根据Market Id查询其所有摄像头的全部信息
     *
     * @param param Market Id
     * @return
     */
    public PageData<Camera> pageFindByMarketId(PageParam<Integer> param) {
        String select = "SELECT c.* ";
        String exceptSelect = " FROM camera c, camera_market s" +
                " WHERE c.id=s.camera_id AND s.market_id=? AND c.status=1";

        Page<Camera> page = this.paginate(param.getPageNo(), param.getPageSize(), select, exceptSelect, param.getP());
        return PageUtil.to(page);
    }

    /**
     * 根据Market Id查询其所有摄像头的主要信息
     *
     * @param param Market Id
     * @return
     */
    public PageData<Camera> pageFindTinyCameraByMarketId(PageParam<Integer> param) {
        String select = "SELECT c.camera_id, c.device_id, c.device_serial, c.pic_url ";
        String exceptSelect = " FROM camera c, camera_market s WHERE c.id=s.camera_id AND s.market_id=? AND c.status=1";

        Page<Camera> page = this.paginate(param.getPageNo(), param.getPageSize(), select, exceptSelect, param.getP());
        return PageUtil.to(page);
    }

    /**
     * 根据设备ID查询其摄像头的信息
     *
     * @param deviceId 设备ID
     * @return
     */
    public Camera findByDeviceId(String deviceId){
        String sql = "select * from camera where device_id=?";
        return this.findFirst(sql, deviceId);
    }


}
